package com.woniuxy.pxxt.controller;

import com.woniuxy.pxxt.common.result.Result;
import com.woniuxy.pxxt.common.vo.CourseEditVo;
import com.woniuxy.pxxt.common.vo.CourseEttVo;
import com.woniuxy.pxxt.common.vo.SelectTrainVo;
import com.woniuxy.pxxt.common.vo.UserTrainAndCourseMsgVo;
import com.woniuxy.pxxt.common.vo.train.SetUserTrainVo;
import com.woniuxy.pxxt.dto.UserDtoSkc;
import com.woniuxy.pxxt.dto.UserMsgDtoSkc;
import com.woniuxy.pxxt.dto.UserTrainDtoSkc;
import com.woniuxy.pxxt.entity.User;
import com.woniuxy.pxxt.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;

/**
 * <P> @Author: ideaAdmin
 * <P> TODO: Class
 * <P> TODO:
 * <P> Date: 2022/3/7:13:23
 * <P> Description:
 */
@Api(value = "处理user的controller")
@RestController
@RequestMapping("/user")
@CrossOrigin
public class UserController {
    @Autowired
    private UserService userService;

    @ApiOperation(value = "通过userid 获得user")
    @GetMapping("/findById/{id}")
    public Result findById(@PathVariable @ApiParam(value = "用户id") Integer id){
        return Result.ok(userService.findById(id));
    }

    @ApiOperation(value = "使用 用户id 加入到当前培训项目")
    @PostMapping("/null")
    public Result addTrain(@RequestBody SetUserTrainVo setUserTrainVo){
        //userService.addUserToTrain(setUserTrainVo);
        return null;
    }


    @ApiOperation(value = "通过用户id 获取其信息")
    @GetMapping("/findUserMsg/{userId}")
    public Result findUserMsg(@PathVariable Integer userId){

        return userService.findUserMsg(userId);
    }

    @ApiOperation(value = "通过用户id获取他参与培训项目的所有信息")
    @PostMapping("/findUserAllTrain")
    public Result findUserAllTrain(@RequestBody SelectTrainVo selectTrainVo) throws ParseException {
        return userService.findUserAllTrain(selectTrainVo);
    }


    @ApiOperation(value = "查询出所有负责人")
    @GetMapping("/findManagerPerson")
    public Result findManagerPerson(){
        return userService.findManagerPerson();
    }

    @ApiOperation(value = "修改用户的信息")
    @PutMapping ("/updateUser")
    public Result updateUser(@RequestBody UserMsgDtoSkc userMsgDtoSkc){
        return userService.updateUser(userMsgDtoSkc);
    }


    @ApiOperation(value = "获取用户的课程 培训信息 进行管理")
    @PostMapping ("/getUserAllMsg/{currentPage}/{pageSize}")
    public Result getUserAllMsg(@PathVariable Integer currentPage,
                                @PathVariable Integer pageSize,
                                @RequestBody UserTrainAndCourseMsgVo userTrainAndCourseMsgVo){
        return userService.getUserAllMsg(currentPage,pageSize,userTrainAndCourseMsgVo);
    }

    @ApiOperation(value = "增加用户")
    @PostMapping ("/addOneUser")
    public Result addOneUser(@RequestBody UserMsgDtoSkc userMsgDtoSkc){
        return userService.addOne(userMsgDtoSkc);
    }

    @ApiOperation(value = "查找用户课程")
    @PostMapping ("/findUserCourse/{userId}")
    public Result getUserAllCourse(@PathVariable Integer userId){
        return userService.findAllCourse(userId);
    }



    @ApiOperation(value = "用户登录方法")
    @PostMapping ("/login")
    public Result userLogin(@RequestBody User user){
        return userService.userLogin(user);
    }

    @ApiOperation(value = "查找用户是否有某些课程")
    @PostMapping ("/findUserSomeCourse")
    public Result getUserSomeCourse(@RequestBody CourseEttVo courseEttVo){
        return userService.findSomeCourse(courseEttVo);
    }
}
